const http = require('http')
const axios = require('axios')
const Url = require('url-parse')
const $ = require('jquery')

let app = http.createServer((req,res)=> {

    res.setHeader("Content-Type", 'text/html;charset=utf-8') // 设置编码格式 解决中文乱码的问题
    res.setHeader("Access-Control-Allow-Origin", '*') 

  let urls = req.url
  let obj = Url(urls,true).query
  var str = null
    console.log(obj)

    axios.post('http://www.liulongbin.top:3006/api/addbook', obj)
            .then((response) => {
                console.log(response.data)
                str = JSON.stringify(response.data)
                console.log(str)
                res.write(str || JSON.stringify('fail'))
                 res.end()
            })
            .catch((err) => console.log('err'))
})

app.listen(3000,()=> {
    console.log('3000 run')
})